#!/usr/bin/env python
#coding=utf-8

import os 

#list 切片;
L=["A","B","C","Aa","Ba","Ca"]
r=[]
for i in range (len(L)):
	r.append(L[i])
print r

print r[0:4]

print r[:4]
print r[-1]
print r[-2:-1]

K=range(100)

print K[10:20]

print K[:10:2]

print K[:]


print (1,2,3,4,5)[:3]


for key in K :
	print key


d={
	"a":1,
	'b':2,
	'c':3
}

for key in d.itervalues() :
	print key

for i ,value in enumerate(['a','b']):
	print i , value 

print range(1,11)

print [ x*x for x in range(1,11) if(x%2==0)]

print [m+n for m in "XYZ" for n in "ABC" ]

print [d for d in os.listdir('.')]

dd = {'x':'A', 'y':'B', 'z':'C' }

print [ i+'='+j for i , j in dd.iteritems() ]

x="aaaa"
print isinstance (x ,str)

def fib(max):
	i ,first , last = 0 ,1 ,1
	while i < max :
		print last
		last,first=first+last,last
		i+=1;

def add(x,y):
	return x+y
print reduce(add,[1,2,3,4,5,6,67])



def char2num(s):
	return {'0':0,'1':1}[s]

print char2num('0')

g = lambda x : x**2;
print g(3)


s="this is s  \naaaaaa\ttest"
print s.split()
print "X".join(s.split()) 


def not_empty(s):
	return s and s.strip()



liebiao=[36, 5, 12, 9, 21]
print sorted(liebiao, lambda x, y: y - x)




def count():
	fs=[]
	for i in range(1,4):
		def f():
			return i*i;
		fs.append(f)

	return fs

f1,f2,f3 = count();


print map(lambda x : x*x ,[1,2,3,4])


def log(func):
	def wrapper(*args,**k1w):
		print "call %s()"%func.__name__
		print args ,k1w
		return func(*args,**k1w)
	return wrapper
@log
def now():
	print '2014-09-01'

now()

def log(arg):
    if callable(arg):
        # @log 模式
        func = arg
        @functools.wraps(func)
        def wrapper(*args, **kw):
            ...
        return wrapper
    else:
        # @log('arg') 模式：
        def decorator(func):
            @functools.wraps(func)
            def wrapper(*args, **kw):
                ...
            return wrapper
        return decorator